﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class makedal
    {
        /// <summary>
        /// 房间预约
        /// </summary>
        /// <param name="ma"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static int insertmake(makemodel ma, string id)
        {
            string sql = string.Format("insert into make values(@rommid,@begtime,@endtime,@people)");

            SqlParameter[] para = new SqlParameter[] {
                new  SqlParameter("@rommid",id),
                 new   SqlParameter("@begtime",ma.begtime),
                  new   SqlParameter("@endtime",ma.endtime),
               new SqlParameter("@people",ma.people),

            };
            int reader = DBhelper.executenonquery(sql, para);
            return reader;
        }
        /* //查询到当前客户与预定的房间
         public static makemodel descmake()
         {
             string sqlstr = "select top 1 * from make order by mid desc";
             SqlParameter[] para = new SqlParameter[]
             {
                 new SqlParameter(),
             };
             SqlDataReader reader = DBhelper.ExecuteReaders(sqlstr,para);
             List<makemodel> list = new List<makemodel>();
             while (reader.Read())
             {
                 makemodel ma = new makemodel();
                 ma.mid =Convert.ToInt32( reader["mid"]);
                 list.Add(ma);
             }
             reader.Close();
             return list[0];
         }*/
        /// <summary>
        /// 显示个人中心的预约信息
        /// </summary>
        /// <param name="roomtid"></param>
        /// <returns></returns>
        public static List<MakeroomModel> showmakeroom(string roomtid)
        {
            string sqlstr = "select * from make a inner join roomtypes b on a.rommid=b.roomtid where b.roomtid=@roomtid and a.mid=(select   top 1 a.mid from make order by mid desc)";
            SqlParameter[] para = new SqlParameter[]
            {
                    new SqlParameter("@roomtid",roomtid),
                };
            SqlDataReader reader = DBhelper.ExecuteReaders(sqlstr, para);
            List<MakeroomModel> list = new List<MakeroomModel>();
            while (reader.Read())
            {
                MakeroomModel mr = new MakeroomModel();
                mr.roomtype = reader["roomtype"].ToString();
                mr.price = Convert.ToInt32(reader["price"]);
                mr.begtime = Convert.ToDateTime(reader["begtime"]);
                mr.endtime = Convert.ToDateTime(reader["endtime"]);
                mr.people = Convert.ToInt32(reader["people"]);
                list.Add(mr);
            }
            reader.Close();
            return list;
        }
        /// <summary>
        /// 删除预约信息
        /// </summary>
        /// <returns></returns>
        public static int DeleteMake(string id)
        {
            string sqlstr = "delete from make where mid=@mid";
            SqlParameter[] para = new SqlParameter[]
            {
                new SqlParameter("@mid",id),
            };
            int r = DBhelper.executenonquery(sqlstr, para);
            return r;
        }
    }
}
